package cc.wsyw126.java.interview.toutiao;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[][] ints = new int[n][n];
        String s = sc.nextLine();
        String[] split = s.split(" ");
        List<String> strings = Arrays.asList(split);
        int max =0;
        for (int i = 0; i < n; i++) {
            int min= Integer.parseInt(strings.get(i)),sum = 0;
            for (int j = i; j < n; j++) {
                int i1 = Integer.parseInt(strings.get(j));
                if (i1 <min) {
                    min= i1;
                }
                sum+=i1;
                if (sum * min>max) {
                    max=sum * min;
                }
            }
        }
        System.out.println(max);
    }
}
